package payPakage.wxH5Play;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import androidx.appcompat.app.AppCompatActivity;

import java.util.ArrayList;
import java.util.HashMap;

public class WXH5PlayActivity extends AppCompatActivity {
    private WebView webview;
    private String type="1";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        String payUrl=getIntent().getStringExtra("payUrl");
        webview=new WebView(this);
        WebSettings webSettings = webview.getSettings();
        webSettings.setJavaScriptEnabled(true);
        webSettings.setUseWideViewPort(true);
        webSettings.setLoadWithOverviewMode(true);
        webview.setWebViewClient(new WebViewClient(){
            @Override
            public boolean shouldOverrideUrlLoading(final WebView view, String url) {
                // 微信逻辑
                if (url.startsWith("weixin://wap/pay?")) {
                    Intent intent = new Intent();
                    intent.setAction(Intent.ACTION_VIEW);
                    intent.setData(Uri.parse(url));
                    WXH5PlayActivity.this.startActivity(intent);
                }
                return super.shouldOverrideUrlLoading(view, url);
            }
        });
        String referer = "https://api.xinanyun.cn";
        HashMap<String, String> extraHeaders = new HashMap<String, String>();
        extraHeaders.put("Referer", referer);
        webview.loadUrl(payUrl,extraHeaders);

    }

    @Override
    protected void onResume() {
        super.onResume();
        if (type=="0"){
            if (WXH5PayPlugin.result!=null){
                WXH5PayPlugin.result.success("success");
            }
            finish();
        }

    }

    @Override
    protected void onPause() {
        super.onPause();
        type="0";
    }
}
